#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>

int main(int argc, char* argv[])
{
    char devname[] = "/dev/chardev";
    int fd;
    fd = open(devname, O_RDWR);
    if (fd <= 0) {
        perror("open dev failed");
        return 1;
    }

    int ret;
    int data = 0x2020;

    ret = write(fd, &data, sizeof(data));
    if (ret > 0) {
        printf("写 %s 设备 1字节成功\n", devname);
    }
    else {
        printf("error 写 %s 设备 1字节失败\n", devname);
    }

    sleep(1);
    ret = read(fd, &data, sizeof(data));
    if (ret > 0) {
        printf("读 %s 设备成功, data=%X\n", devname, data);
    }
    else {
        printf("error 读 %s 设备 失败\n", devname);
    }


    return 0;
}